﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EduseKiosk
{
    public partial class FormEduseKiosk : Form
    {
        //see the difference in ohter computer
        private static FormEduseKiosk formInstance;
        private ViewControl activeViewControl;
        private ViewControl previousViewControl;

        private FormEduseKiosk()
        {
            InitializeComponent();
        }

        public static FormEduseKiosk Instance
        {
            get
            {
                if (formInstance == null)
                    formInstance = new FormEduseKiosk();

                return formInstance;
            }
            set
            {
                formInstance = value;
            }
        }

        public ViewControl ActiveViewControl
        {
            get { return activeViewControl; }
            set { activeViewControl = value; }
        }

        public TopBar TopBar
        {
            get { return topBar; }
            set { topBar = value; }
        }

        public NavBar NavBar
        {
            get { return navBar; }
            set { navBar = value; }
        }

        public LeftBarThumbnails LeftBarThumbnails
        {
            get { return leftBarThumbnails; }
            set { leftBarThumbnails = value; }
        }

        public LeftBarTTopics LeftBarTTopics
        {
            get { return leftBarTTopics; }
            set { leftBarTTopics = value; }
        }

        public LeftBarHidden LeftBarHidden
        {
            get { return leftBarHidden; }
            set { leftBarHidden = value; }
        }

        public Panel PanelView
        {
            get { return panelView; }
            set { panelView = value; }
        }

        public bool LeftBarThumbnailsActive
        {
            get
            {
                return leftBarThumbnails.Visible;
            }
            set
            {
                leftBarThumbnails.Visible = value;
                leftBarHidden.Visible = !value;
            }
        }

        public bool LeftBarTopicsActive
        {
            get
            {
                return leftBarTTopics.Visible;
            }
            set
            {
                leftBarTTopics.Visible = value;
                leftBarHidden.Visible = !value;
            }
        }

        public void SwitchToView(ViewControl viewControl)
        {
            int index = 0;

            if (activeViewControl != null)
            {
                index = panelView.Controls.IndexOf(activeViewControl);
                panelView.Controls.Remove(activeViewControl);
            }

            

            previousViewControl = activeViewControl;
            activeViewControl = viewControl;
            panelView.Controls.Add(activeViewControl);
            panelView.Controls.SetChildIndex(activeViewControl, index);

            topBar.Department = activeViewControl.Department;
            topBar.Course = activeViewControl.Course;
            topBar.Chapter = activeViewControl.Chapter;
            topBar.Section = activeViewControl.Section;
            topBar.Type = activeViewControl.Type;
            topBar.SearchBarActive = true;

            navBar.Reload();
        }

        public void SwitchToPreviousView()
        {
            SwitchToView(previousViewControl);
        }

        /*
        public void toggleLeftBar()
        {
            leftBar.Visible = leftBar.Enabled = !leftBar.Enabled;
            leftBarHidden.Visible = leftBarHidden.Enabled = !leftBar.Enabled;
        }

        public void toggleRightBar()
        {
            rightBar.Visible = rightBar.Enabled = !rightBar.Enabled;
            rightBarHidden.Visible = rightBarHidden.Enabled = !rightBar.Enabled;
        }
         * */

        private void FormEduseKiosk_Load(object sender, EventArgs e)
        {
            LeftBarThumbnailsActive = false;
            LeftBarTopicsActive = false;
            
            SwitchToView(new WelcomeView());
        }
    }
}
